package com.zlm.user.emp.controller;

import com.zlm.common.base.BaseController;
import com.zlm.common.base.PageEntity;
import com.zlm.common.constants.CodeConstants;
import com.zlm.common.dto.JsonResultDto;
import com.zlm.common.dto.userEmp.OrgCollectParamsDto;
import com.zlm.user.emp.service.EmpOrgCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 公司收藏controller
 * @Author: duyufu
 * @Date: 2019/5/5 13:55
 */
@RestController
@RequestMapping(value = "/empOrgCollect")
public class EmpOrgCollectController extends BaseController {

    @Autowired
    private EmpOrgCollectService empOrgCollectService;

    /**
     * 保存公司收藏
     * @param operationCode
     * @param orgId
     * @param empId
     * @return
     */
    @GetMapping("/saveEmpOrgCollect")
    public JsonResultDto saveEmpOrgCollect(Integer operationCode, Integer orgId, Integer empId) {
        try {
            String result = empOrgCollectService.saveEmpOrgCollect(operationCode,orgId,empId);
            if (CodeConstants.CODE_SUCCESS.equals(result)) {
                return success();
            }else {
                return fail(result);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return fail(CodeConstants.CODE_BUSY);
        }
    }

    /**
     * 查询公司收藏列表
     * @param orgCollectParamsDto
     * @return
     */
    @PostMapping("/queryEmpOrgCollect")
    public JsonResultDto queryEmpOrgCollect(@RequestBody OrgCollectParamsDto orgCollectParamsDto) {
        try {
            PageEntity page = empOrgCollectService.queryEmpOrgCollect(orgCollectParamsDto.getEmpId(),
                    orgCollectParamsDto.getPageSize(),orgCollectParamsDto.getPageNumber());
            return success(page);
        } catch (Exception e) {
            e.printStackTrace();
            return fail(CodeConstants.CODE_BUSY);
        }
    }
}
